/**
 * ****************************************************************************
 * Project: RoboBridge
 * ----------------------------------------------------------------------------
 * -------------------------- [c]2012 - KrawallMann ---------------------------
 * ---------------------- http://www.krawallmann.de.tc/ -----------------------
 * ****************************************************************************
 * File: BitOperations.java Package: tc.de.krawallmann.robobridge.util Version:
 * 1.0 Author(s): KrawallMann
 * ****************************************************************************
 * Description:
 * ****************************************************************************
 */
package tc.de.krawallmann.robobridge.util;

/**
 * The Class BitOperations provides helpful bit operations.<br/>
 * 
 * @author KrawallMann
 * @version 1.0
 */
public final class BitOperations {

	/**
	 * Combine high low.
	 * 
	 * @param highByte
	 *            the high byte
	 * @param lowByte
	 *            the low byte
	 * @return the int
	 */
	public static int combineHighLow(final int highByte, final int lowByte) {
		return ((highByte & 0x000000FF) << 8) + (lowByte & 0x000000FF);
	}

	/**
	 * Gets the high byte.
	 * 
	 * @param int16
	 *            the int16
	 * @return the high byte
	 */
	public static int getHighByte(final int int16) {
		return (int16 & 0x0000FF00) >> 8;
	}

	/**
	 * Gets the low byte.
	 * 
	 * @param int16
	 *            the int16
	 * @return the low byte
	 */
	public static int getLowByte(final int int16) {
		return int16 & 0x000000FF;
	}

	/**
	 * Checks if is bit set.
	 * 
	 * @param theInt
	 *            the the int
	 * @param pos
	 *            the pos
	 * @return true, if is bit set
	 */
	public static boolean isBitSet(final int theInt, final int pos) {
		return (theInt & 1 << pos) != 0;
	}

	/**
	 * Checks if is int16.
	 * 
	 * @param theInt
	 *            the the int
	 * @return true, if is int16
	 */
	public static boolean isInt16(final int theInt) {
		return theInt < 0x7fff && theInt > -0x7fff - 1;
	}

	/**
	 * Instantiates a new bit operations.
	 */
	private BitOperations() {
		// Avoids instantiations of this utility class
	}
}
